# 移动各级目录下的图片至指定文件夹

import os
import shutil

def move_jpg_files(source_dir, destination_dir):
    # 遍历源目录下的所有子目录和文件
    for root, dirs, files in os.walk(source_dir):
        for file in files:
            # 判断文件扩展名是否为jpg
            if file.endswith('.jpg'):
                # 构建源文件路径和目标文件路径
                source_file_path = os.path.join(root, file)
                destination_file_path = os.path.join(destination_dir, file)
                # 移动文件
                shutil.move(source_file_path, destination_file_path)
                print(f"Moved file: {source_file_path} to {destination_file_path}")

# 指定源目录和目标目录
source_directory = 'C:/Users/22191/Desktop/数据集'
destination_directory = 'C:/Users/22191/Desktop/数据集'

# 调用函数移动jpg文件
move_jpg_files(source_directory, destination_directory)